const path = require('path')

module.exports = {
  entry: "./src/main.js",
  output: {
    filename: 'bundle.js',
    // 必须是一个绝对路径
    path: path.resolve(__dirname, './build')
  },
  module: {
    // rule对象
    rules: [
      {
        // 匹配资源 正则表达式
        test: /\.css$/,
        // loader: 'css-loader' use 简写
        use: [
          // 编译顺序：从后往前，从下往上
          // useEntry 对象
          // { loader: 'css-loader' }
          // 'css-loader' { loader: 'css-loader' } 简写5
          "style-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1
            }
          },
          "postcss-loader"
        ]
      },
      {
        test: /\.less$/,
        use: [
          'style-loader',
          {
            loader: "css-loader",
            options: {
              importLoaders: 2
            }
          },
          "postcss-loader",
          'less-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)$/,
        use: [
          {
            // loader: 'file-loader',
            loader: 'url-loader',
            options: {
              name: 'img/[name][hash:6].[ext]',
              // outputPath: 'img'
              limit: 2 * 1024 * 1024
            }
          }
        ]
      }
    ]
  }
}